﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>菜品列表</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link href="/View_Mobile/Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <link href="/View_Mobile/CSS/fs_gallery.css" rel="stylesheet" />
    <script src="/View_Mobile/JS/layer/layer.m.js"></script>
    <script src="/View_Mobile/JS/zepto.min.js"></script>
    <script src="/View_Mobile/Frozenui1.3/js/frozen.js"></script>
    <script src="/View_Mobile/JS/ComFunJS.js?jsver=20160425"></script>
    <script src="/View_Mobile/JS/avalon.mobile.min.js"></script>

    <style type="text/css">
        /*.ui-header {background-color: #06c1ae;color: #fff;}
        .ui-header h1{color:#fff;}
        .bar .button-link{color:#fff;}*/
        .ui-checkbox input:before {
            line-height:normal;
        }
         .ms-controller, [ms-controller] {
            display: none;
        }

        .bq {
            text-align: center;
            position: absolute;
            top: 0.05rem;
            right: 0.05rem;
            width: 0.2rem;
            height: 0.2rem;
            line-height: 0.2rem;
            font-size: 0.15rem;
            color: #fff;
            background-color: #FF5151;
            border-radius: 0.1rem;
        }

        .current {
            background-color: white;
        }

        .addmin {
            position: absolute;
            right: 0.1rem;
            width: 0.9rem;
            height: 0.3rem;
        }

            .addmin input {
                width: 0.28rem;
                height: 0.28rem;
                font-size: 0.18rem;
                border: 1px solid #e5e5e5;
                text-align: center;
                color: #A1A09C;
                background-color: #fff;
            }
    </style>

</head>
<body ms-controller="model" style="background-color: #E5E5E5; ">
    <!--style="top: 0; height: 45px; line-height: 45px; text-align: center;"-->
    <!--<header class="ui-border-b ui-header ui-header-stable ui-border-b" >
        <h1>菜单</h1>
    </header>-->
    <section class="ui-container" style="margin-bottom:40px;">
        <div class="ui-row-flex">
            <div class="ui-col ui-col-1">
                <ul class="ui-list ui-list-text tplist" style="background-color: #E5E5E5; position: fixed; width: 25%; z-index: 100; left: 0;">
                    <li ms-repeat-el="ctData" ms-click="ckcp(this)" style="margin:0;padding-left:15px;" ms-attr-class="$index==0?' ui-border-b current':'ui-border-b'">
                        <div class="ui-list-info">
                            <a ms-attr-href="'#st'+el.ID">{{el.TypeName}}</a>
                        </div>
                        <b class="bq" ms-if="el.Qty!='0'">{{el.Qty}}</b>
                    </li>
                </ul>
            </div>
            <div class="ui-col ui-col-3">
                <div ms-repeat-st="ctData" ms-attr-id="'st'+st.ID" class="cplist">
                    <div style="text-align: center; color: #a7a7a7; border-left: solid 1px white; height: 44px; line-height: 44px; font-size: 20px;" class="ui-border-b">{{st.TypeName}}</div>
                    <ul class="ui-list">
                        <li class="ui-border-b" ms-repeat-item="st.Item" ms-visible="isbj||item.Status=='1'" style="margin:0;">
                            <div>
                                <img ms-attr-src="'/ViewV5/Base/DownFile.aspx?fileId='+item.ImgUrl" style="width:80px;height:60px;padding:5px;" />
                            </div>
                            <div class="ui-list-info" style="padding:0;">
                                <div style="display: -webkit-box;">
                                    <div style="-webkit-box-flex:1">
                                        <h4 class="ui-nowrap" style="line-height:20px;">{{item.Name}}</h4>
                                        <p class="ui-nowrap" style="line-height:20px;font-size:12px;">上架时间：{{item.CRDate.substring(5,10)}}</p>
                                    </div>
                                    <div class="ui-form-item ui-form-item-checkbox" style="padding: 0; float: right; line-height: normal;height:auto;" ms-if="isbj">
                                        <label class="ui-checkbox">
                                            <input type="checkbox" ms-attr-value="item.ID">
                                        </label>
                                    </div>
                                </div>
                                    <div style="display: -webkit-box;">
                                        <div>
                                            <span class="ui-nowrap" style="color: #FF5151;font-size:14px;"> ¥<span class="price">{{item.Price.toFixed(2)}}</span>/份</span>
                                        </div>
                                        <div class="ui-list-info" style="padding:0;">
                                            <span class="addmin" ms-if="!isbj" style="width:auto;">
                                                <input type="button" class="minus" value="-" ms-click="minus(item,st)">
                                                <input type="text" class="result" readonly ms-duplex="item.Qty" style="border: none; color: #FF5151;">
                                                <input type="button" class="add" value="+" ms-click="add(item,st)">
                                            </span>
                                            <span class="addmin" ms-if="isbj" style="text-align: right; width: auto;">
                                                <input type="button" class="result" readonly value="↓" style="border: none; color: #FF5151;" ms-if="item.Status=='0'">
                                                <input type="button" class="ui-btn ui-btn-primary" value="编辑" ms-click="update(item)" style="width: auto; line-height: 0.28rem; padding: 0; min-width: 45px;color:white;">
                                            </span>
                                        </div>
                                    </div>

                                </div>
                        </li>
                        <li class="ui-border-b" ms-if="(st.xsQty=='0' && !isbj) || st.Item.size()==0" style="margin: 0; text-align: center;">
                            <div style="width: 100%; height: 72px; line-height: 72px;">无菜品</div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </section>
    <footer class="ui-footer ui-footer-stable ui-border-t" style="height:40px;" ms-if="!isbj">
        <div style="padding-left:5px; padding-right:10px;height:40px;line-height:40px;">
            合计:¥<span class="ui-txt-warning" style="font-weight:bold;">{{totalprice.toFixed(2)}}</span>({{totalqty}}份)
            <a class="ui-btn ui-btn-primary" style="float: right; width: 80px; margin-top: 5px;" ms-click="savedata()">选好了</a>
        </div>
    </footer>
    <footer class="ui-footer ui-footer-stable ui-border-t ui-btn-group" style="height:40px;" ms-if="isbj">
        <button class="ui-btn ui-btn-primary" ms-click="addcp()">新增菜品</button>
        <button class="ui-btn ui-btn-danger" ms-click="xjcp()">下架菜品</button>
    </footer>

    <script>
        //document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        //    //隐藏右上角按钮
        //    WeixinJSBridge.call('hideOptionMenu');
        //});

        var model = avalon.define({
            $id: "model",
            ctData: [],
            totalprice: 0,
            totalqty: 0,
            YJYCDate: "",
            isbj: "",
            addcp: function () {
                window.location = "UI_DCGL_INPUT.html?r=" + Math.random();
            },
            xjcp: function () {
                var html = '';
                $("input[type=checkbox]:checked").each(function (index, ele) {
                    if (html) {
                        html = html + ',' + $(ele).val();
                    }
                    else {
                        html = $(ele).val();
                    }
                })
                if (html) {
                    var lg = $.loading({
                        content: '下架中...',
                    })
                    $.getJSON('/API/VIEWAPI.ashx?Action=DCGL_XJCP&r=' + Math.random(), { P1: html }, function (resultData) {

                        if (resultData.ErrorMsg == "") {
                            var el=$.tips({
                                content: "下架成功",
                                stayTime: 2000,
                                type: "warn"
                            })
                            el.on("tips:hide", function () {
                                window.location.replace(window.location+"&v=" + Math.random());
                            })
                        }
                    })
                }
                else {
                    $.tips({
                        content: "请选择菜品!",
                        stayTime: 2000,
                        type: "warn"
                    })
                }
            },
            ckcp: function (obj) {
                $(obj).parent().find("li").removeClass("current");
                $(obj).addClass("current");
                $(obj).find("a").trigger("click");
            },
            add: function (im, el) {
                im.Qty = im.Qty * 1 + 1;
                el.Qty = el.Qty * 1 + 1;
                model.totalqty = model.totalqty * 1 + 1;
                model.totalprice = model.totalprice * 1 + im.Price * 1;
            },
            minus: function (im, el) {
                if (im.Qty * 1 > 0) {
                    im.Qty = im.Qty * 1 - 1;
                    el.Qty = el.Qty * 1 - 1;
                    model.totalqty = model.totalqty * 1 - 1;
                    model.totalprice = model.totalprice * 1 - im.Price * 1;
                }
            },
            update: function (im) {
                window.location = "UI_DCGL_INPUT.html?id=" + im.ID + "&r=" + Math.random();
            },
            savedata: function () {
                var IDS = "";
                $(model.ctData).each(function (rt, ix) {
                    $(ix.Item).each(function (index, ele) {
                        if (ele.Qty * 1 > 0) {
                            if (IDS) {
                                IDS = IDS + "," + ele.ID + "_" + ele.Qty;
                            }
                            else {
                                IDS = ele.ID + "_" + ele.Qty;
                            }
                        }
                    })
                });
                if (!IDS) {
                    $.tips({
                        content: "请选择菜品",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                var tc = layer.open({
                    content: '确定选好了吗？',
                    btn: ['确定', '取消'],
                    shadeClose: false,
                    yes: function () {
                        layer.close(tc);

                        var lg = $.loading({
                            content: '处理中...',
                        })

                        var date = new Date();
                        var d = {
                            "YJYCDate": model.YJYCDate,
                            "IDS": IDS
                        };

                        $.post("/API/VIEWAPI.ashx?Action=DCGL_ADDDCGLDD&r=" + Math.random(), { "P1": JSON.stringify(d) }, function (data) {
                            lg.hide();
                            var data = $.parseJSON(data);
                            if (data.ErrorMsg == "") {
                                $(".ui-footer").hide();
                                var el = $.tips({
                                    content: "下单成功！",
                                    stayTime: 2000,
                                    type: "success"
                                })
                                el.on("tips:hide", function () {
                                    window.history.back();
                                })

                            }
                            else {
                                if (data.Result) {
                                    var html = '';
                                    var cl = data.Result.split(',');
                                    $(cl).each(function (index, ele) {
                                        $(model.ctData).each(function (inx,cdt) {
                                            cdt.Item.each(function (ine,cp) {
                                                if (cp.ID.toString() == ele) {
                                                    if (html) {
                                                        html = html + ',' + cp.Name;
                                                    }
                                                    else {
                                                        html = cp.Name;
                                                    }

                                                    cdt.Qty = cdt.Qty * 1 - cp.Qty;
                                                    model.totalqty = model.totalqty * 1 - cp.Qty;
                                                    model.totalprice = model.totalprice * 1 - cp.Price * cp.Qty;
                                                    
                                                    cdt.Item.remove(cp);
                                                }
                                            })
                                        })
                                    })
                                    $.tips({
                                        content: "下单失败，" + html+"已下架",
                                        stayTime: 2000,
                                        type: "warn"
                                    })
                                }
                                else {
                                    $.tips({
                                        content: "下单失败，原因：" + data.ErrorMsg,
                                        stayTime: 2000,
                                        type: "warn"
                                    })
                                }
                            }
                        })
                    }, no: function () {
                    }
                })

            }

        });

        var strType = ComFunJS.getQueryString("type");

        avalon.ready(function () {
            var lg = $.loading({
                content: '加载中...',
            })
            $.getJSON("/API/VIEWAPI.ashx?Action=XTGL_GETCPROLE&r=" + Math.random(), {}, function (r) {
                if (r.ErrorMsg == "") {
                    if (r.Result == "Y") {
                        if (strType == "2") {
                            model.isbj = "Y";
                        }
                    }
                }
            })
            $.post("/API/VIEWAPI.ashx?Action=DCGL_GETDCGLLIST_PAGE&r=" + Math.random(), {}, function (data) {
                lg.hide();
                var data = $.parseJSON(data);
                if (data.ErrorMsg == "") {
                    model.ctData = data.Result;
                }
            })
        })

        $(window).scroll(function () {

            for (var i = 0; i < $(".cplist").length; i++) {
                var sheight = 0;
                for (var j = 0; j < i; j++) {
                    sheight = sheight + $(".cplist").eq(j).height();
                }
                if ($(this).scrollTop() > sheight - 77) {
                    $(".tplist li").removeClass("current");
                    $(".tplist li").eq(i).addClass("current");
                }
            }
            if ($(document).height() == $(this).scrollTop() + $(this).height()) {
                $(".tplist li").removeClass("current");
                $(".tplist li").eq($(".cplist").length - 1).addClass("current");
            }
        })

        function back() {
            window.history.back();
        }
    </script>
</body>







</html>
